//
// Created by LONG on 2020/10/27.
//

#ifndef CSP_INCLUDE_UTILS_WHEELTIMER_H_
#define CSP_INCLUDE_UTILS_WHEELTIMER_H_

#include "commDef.h"
#include "list.h"

#ifdef __cplusplus
extern "C"
{
#endif

/******************************************************************************
 wheel timer : 时间轮定时器。
 ******************************************************************************/

enum
{
    TIMER_TYPE_ONCE, /* 只运行一次 */
    TIMER_TYPE_LOOP, /* 循环运行 */
    TIMER_TYPE_BUTT
};

enum
{
    TIMER_STATE_STOP,
    TIMER_STATE_START,
    TIMER_STATE_TIMEOUT,
    TIMER_STATE_BUTT
};

typedef void (*WheelTimerCallback)(void *arg);
typedef struct WtWheel S_WtWheel;
typedef struct WtTimer S_WtTimer;

S_WtWheel *WT_CreateWheel(const char *name);
void WT_DestroyWheel(S_WtWheel *wheel);
S_WtTimer* WT_CreateTimer(void);
void WT_DestroyTimer(S_WtTimer *timer);
int32_t WT_StartTimer(S_WtWheel *wheel, S_WtTimer *timer, WheelTimerCallback callback, void *arg, uint32_t type, uint32_t delay);
int32_t WT_StopTimer(S_WtTimer *timer);
int32_t WT_TimerState(S_WtTimer *timer);
void WT_Run(S_WtWheel *wheel, uint32_t step);


#ifdef __cplusplus
}
#endif

#endif //CSP_INCLUDE_UTILS_WHEELTIMER_H_
